package airarmory.define
{
	import mx.collections.ArrayCollection;
	
	public class ItemConst
	{
		public static var SLOT_OBEJCT:Object = getSlotObject();
		
		private static function getSlotObject():Object
		{
			var o:Object = new Object();
			var index:int = 1;
			o["Head"] = index++;
			o["Shoulder"] = index++;
			o["Chest"] = index++;
			o["Wrist"] = index++;
			o["Hands"] = index++;
			o["Waist"] = index++;
			o["Legs"] = index++;
			o["Feet"] = index++;
			o["Held in Off-hand"] = index++;
			o["Finger"] = index++;
			o["Trinket"] = index++;
			o["Neck"] = index++;
			o["Back"] = index++;
			o["Main Hand"] = index++;
			o["One-Hand"] = index++;
			o["Off Hand"] = index++;
			o["Two-Hand"] = index++;
			o["Ranged"] = index++;
			o["Thrown"] = index++;
			o["Relic"] = index++;
			// "*" is unknown
			return o;
		}
		public static function isWeaponSlot(slot:String):Boolean
		{
			return slot == "Main Hand"
				|| slot == "Off Hand"
				|| slot == "One-Hand"
				|| slot == "Two-Hand";
		}
		public static function isAllClassesSlot(slot:String):Boolean
		{
			return slot == "Finger"
				|| slot == "Trinket"
				|| slot == "Neck"
				|| slot == "Back";
		}

		public static var TYPE_OBEJCT:Object = getTypeObject();
		
		private static function getTypeObject():Object
		{
			var o:Object = new Object();
			var index:int = 1;
			o["Cloth"] = index++;
			o["Leather"] = index++;
			o["Mail"] = index++;
			o["Plate"] = index++;
			o["Shield"] = index++;
			o["Held in Off-hand"] = index++;
			o["Finger"] = index++;
			o["Trinket"] = index++;
			o["Neck"] = index++;
			o["Back"] = index++;
			o["Axe"] = index++;
			o["Mace"] = index++;
			o["Sword"] = index++;
			o["Fist Weapon"] = index++;
			o["Dagger"] = index++;
			o["Axe"] = index++;
			o["Mace"] = index++;
			o["Polearm"] = index++;
			o["Sword"] = index++;
			o["Staff"] = index++;
			o["Gun"] = index++;
			o["Bow"] = index++;
			o["Thrown"] = index++;
			o["Crossbow"] = index++;
			o["Wand"] = index++;
			o["Idol"] = index++;
			o["Libram"] = index++;
			o["Totem"] = index++;
			o["Sigil"] = index++;
			// "*" is unknown
			return o;
		}
		
		private static const TANK_PROPERTY_1:String = "defense rating";
		private static const TANK_PROPERTY_2:String = "dodge rating";
		
		public static function hasTankProperty(line:String):Boolean
		{
			if(line.indexOf("Equip: ") == -1
				&& line.indexOf("Use: ") == -1)
				return false;
			else
				return line.indexOf(TANK_PROPERTY_1) != -1
					|| line.indexOf(TANK_PROPERTY_2) != -1;
		}
		
		private static const CASTER_PROPERTY_1:String = "spell power";
		private static const CASTER_PROPERTY_2:String = "Restores";
		
		public static function hasCasterProperty(line:String):Boolean
		{
			if(line.indexOf("Equip: ") == -1
				&& line.indexOf("Use: ") == -1)
				return false;
			else
				return line.indexOf(CASTER_PROPERTY_1) != -1
				|| line.indexOf(CASTER_PROPERTY_2) != -1
		}
		
		private static const MELEE_PROPERTY_1:String = "attack power";
		private static const MELEE_PROPERTY_2:String = "armor penetration";
		
		public static function hasMeleeProperty(line:String):Boolean
		{
			if(line.indexOf("Equip: ") == -1
				&& line.indexOf("Use: ") == -1)
				return false;
			else
				return line.indexOf(MELEE_PROPERTY_1) != -1
				|| line.indexOf(MELEE_PROPERTY_2) != -1
		}
		
		private static const IGNORE_ITEM_OBJECT:Object = getIgnoreItemObject();
		
		private static function getIgnoreItemObject():Object
		{
			var o:Object = new Object();
			o["45506"] = true;// Archivum Data Disc
			o["45857"] = true;// Archivum Data Disc
			o["43345"] = true;// Dragon Hide Bag
			o["43345"] = true;// Dragon Hide Bag
			o["43347"] = true;// Satchel of Spoils
			o["43953"] = true;// Reins of the Blue Drake
			o["43952"] = true;// Reins of the Azure Drake
			o["44569"] = true;// Key to the Focusing Iris
			o["44577"] = true;// Heroic Key to the Focusing Iris
			return o;
		}
		public static function isIgnoreItem(item_id:String):Boolean
		{
			return IGNORE_ITEM_OBJECT[item_id] == true;
		}
		public static function getItemID(itemName:String):String
		{
			return ITEM_LIST_XML.wowitem.(@name == itemName).@id;
		}
		public static function getItemName(itemId:String):String
		{
			return ITEM_LIST_XML.wowitem.(@id == itemId).@name;
		}
		
		public static var ITEM_LIST_XML:XML;
	}
}